//2009/08/26 14:37:06
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <sstream>
#include <algorithm>

using namespace std;

int sum_of_name(string s)
{
    int sum = 0;
    for (int i=0; i<s.size(); i++) sum += s[i] - 'A' + 1;
    return sum;
}
bool cmp(const string& a,const string& b)
{
    if (a == "JOHN") return true;
    else if (b != "JOHN" && sum_of_name(a) > sum_of_name(b)) return true;
    else if (sum_of_name(a) == sum_of_name(b) && a < b) return true;
    return false;
}

class TheBestName
{
public:
    vector <string> sort(vector <string> names)
    {
        vector<string> ret(names);
        std :: sort(ret.begin(), ret.end(), cmp);
        return ret;
    }
};
